package com.ruoyi.project.wms.logistics.position.controller;

import java.util.List;

import com.ruoyi.project.wms.logistics.position.domain.WmsPosition;
import com.ruoyi.project.wms.logistics.position.service.IWmsPositionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-09-30
 */
@Controller
@RequestMapping("/logistics/position")
public class WmsPositionController extends BaseController
{
    private String prefix = "wms/logistics/position";

    @Autowired
    private IWmsPositionService wmsPositionService;

    @RequiresPermissions("logistics:position:view")
    @GetMapping()
    public String position()
    {
        return prefix + "/position";
    }

    /**
     * 查询【储位】列表
     */
    @RequiresPermissions("logistics:position:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsPosition wmsPosition)
    {
        startPage();
        List<WmsPosition> list = wmsPositionService.selectWmsPositionList(wmsPosition);
        return getDataTable(list);
    }

    /**
     * 导出【储位信息】
     */
    @RequiresPermissions("logistics:position:export")
    @Log(title = "【储位信息导出】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsPosition wmsPosition)
    {
        List<WmsPosition> list = wmsPositionService.selectWmsPositionList(wmsPosition);
        ExcelUtil<WmsPosition> util = new ExcelUtil<WmsPosition>(WmsPosition.class);
        return util.exportExcel(list, "position");
    }

    /**
     * 新增页面跳转
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增储位功能
     */
    @RequiresPermissions("logistics:position:add")
    @Log(title = "【新增储位】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsPosition wmsPosition)
    {
        return toAjax(wmsPositionService.insertWmsPosition(wmsPosition));
    }

    /**
     * 跳转修改储位界面
     */
    @GetMapping("/edit/{pid}")
    public String edit(@PathVariable("pid") Long pid, ModelMap mmap)
    {
        WmsPosition wmsPosition = wmsPositionService.selectWmsPositionById(pid);
        mmap.put("wmsPosition", wmsPosition);
        return prefix + "/edit";
    }

    /**
     * 修改储位名称
     */
    @RequiresPermissions("logistics:position:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsPosition wmsPosition)
    {
        return toAjax(wmsPositionService.updateWmsPosition(wmsPosition));
    }

    /**
     * 删除储位信息
     */
    @RequiresPermissions("logistics:position:remove")
    @Log(title = "【删除储位信息】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsPositionService.deleteWmsPositionByIds(ids));
    }
}
